home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / config.c < prev    next >
C/C++ Source or Header  |  1994-09-16  |  22KB  |  911 lines

  1. /* A collection of stuff heavily dependent on the configuration info
  2.  * in config.h. The idea is that configuration-dependent tables should
  3.  * be located here to avoid having to pepper lots of .c files with #ifdefs,
  4.  * requiring them to include config.h and be recompiled each time config.h
  5.  * is modified.
  6.  *
  7.  * Copyright 1991 Phil Karn, KA9Q
  8.  */
  9.  
  10. /****************************************************************************
  11. *    $Id: config.c 1.8 94/02/02 14:37:32 ROOT_DOS Exp $
  12. *    09 Aug 92    1.2        GT    Experiment with inline dialer.
  13. *    13 Aug 92    1.3        JB    Pegasus mail stuff.    
  14. *    24 Aug 92    1.4        GT    Time commands.            
  15. *    08 May 93    1.5        GT    Fix warnings.            
  16. *    22 Dec 93    1.6        GT    Batch ftp.                
  17. *    02 Feb 94    1.8        GT    ftpopt.                    
  18. ****************************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include <dos.h>
  22. #include "global.h"
  23. #include "config.h"
  24. #include "mbuf.h"
  25. #include "timer.h"
  26. #include "proc.h"
  27. #include "iface.h"
  28. #include "ip.h"
  29. #include "tcp.h"
  30. #include "udp.h"
  31. #ifdef    ARCNET
  32. #include "arcnet.h"
  33. #endif
  34. #include "lapb.h"
  35. #include "ax25.h"
  36. #include "enet.h"
  37. #include "kiss.h"
  38. #include "nr4.h"
  39. #include "netrom.h"
  40. #include "pktdrvr.h"
  41. #include "ppp.h"
  42. #include "slip.h"
  43. #include "arp.h"
  44. #include "icmp.h"
  45. #include "hardware.h"    /***/
  46. #include "usock.h"
  47. #include "cmdparse.h"
  48. #include "commands.h"
  49. #include "mailbox.h"
  50. #include "ax25mail.h"
  51. #include "nr4mail.h"
  52. #include "tipmail.h"
  53. #include "daemon.h"
  54. #include "bootp.h"
  55. #include "rip.h"
  56.  
  57. int dotest __ARGS((int argc,char *argv[],void *p));    /**/
  58. static int dostart __ARGS((int argc,char *argv[],void *p));
  59. static int dostop __ARGS((int argc,char *argv[],void *p));
  60.  
  61. #ifdef    AX25
  62. static void axip __ARGS((struct iface *iface,struct ax25_cb *axp,char *src,
  63.   char *dest,struct mbuf *bp,int mcast));
  64. static void axarp __ARGS((struct iface *iface,struct ax25_cb *axp,char *src,
  65.   char *dest,struct mbuf *bp,int mcast));
  66. static void axnr __ARGS((struct iface *iface,struct ax25_cb *axp,char *src,
  67.   char *dest,struct mbuf *bp,int mcast));
  68. #endif
  69.  
  70. struct mbuf *Hopper;
  71. unsigned Nsessions = NSESSIONS;
  72.  
  73. /* Free memory threshold, below which things start to happen to conserve
  74.  * memory, like garbage collection, source quenching and refusing connects
  75.  */
  76. int32 Memthresh = MTHRESH;
  77.  
  78. int Nibufs = NIBUFS;        /* Number of interrupt buffers */
  79. unsigned Ibufsize = IBUFSIZE;    /* Size of each interrupt buffer */
  80.  
  81. /* Transport protocols atop IP */
  82. struct iplink Iplink[] = 
  83. {
  84.     { TCP_PTCL,    tcp_input },
  85.     { UDP_PTCL,    udp_input },
  86.     { ICMP_PTCL,    icmp_input },
  87.     { IP_PTCL,    ipip_recv },
  88.     { 0,        0 }
  89. }
  90. ;
  91.  
  92. /* Transport protocols atop ICMP */
  93. struct icmplink Icmplink[] = 
  94. {
  95.     { TCP_PTCL,    tcp_icmp },
  96.     { 0,        0 }
  97. }
  98. ;
  99.  
  100. /* ARP protocol linkages */
  101. struct arp_type Arp_type[NHWTYPES] = 
  102. {
  103. #ifdef    NETROM
  104.     { AXALEN, 0, 0, 0, NULLCHAR, pax25, setcall },    /* ARP_NETROM */
  105. #else
  106.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },
  107. #endif
  108.  
  109. #ifdef    ETHER
  110.     { EADDR_LEN,IP_TYPE,ARP_TYPE,1,Ether_bdcst,pether,gether }, /* ARP_ETHER */
  111. #else
  112.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },
  113. #endif
  114.  
  115.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_EETHER */
  116.  
  117. #ifdef    AX25
  118.     { AXALEN, PID_IP, PID_ARP, 10, Ax25multi[0], pax25, setcall },
  119. #else
  120.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_AX25 */
  121. #endif
  122.  
  123.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_PRONET */
  124.  
  125.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_CHAOS */
  126.  
  127.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_IEEE802 */
  128.  
  129. #ifdef    ARCNET
  130.     { AADDR_LEN, ARC_IP, ARC_ARP, 1, ARC_bdcst, parc, garc }, /* ARP_ARCNET */
  131. #else
  132.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },
  133. #endif
  134.  
  135.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_APPLETALK */
  136. }
  137. ;
  138.  
  139. #ifdef    AX25
  140. /* Linkage to network protocols atop ax25 */
  141. struct axlink Axlink[] = 
  142. {
  143.     { PID_IP,        axip },
  144.     { PID_ARP,    axarp },
  145. #    ifdef    NETROM
  146.     { PID_NETROM,    axnr },
  147. #    endif
  148.     { PID_NO_L3,    axnl3 },
  149.     { 0,        NULL },
  150. }
  151. ;
  152. #endif
  153.  
  154. #ifdef    MAILBOX
  155. void (*Listusers) __ARGS((int s)) = listusers;
  156. #else
  157. void (*Listusers) __ARGS((int s)) = NULL;
  158. #endif
  159.  
  160. #ifndef    BOOTP
  161. int WantBootp = 0;
  162.  
  163. int
  164. bootp_validPacket(ip,bpp)
  165. struct ip *ip;
  166. struct mbuf **bpp;
  167. {
  168.     return 0;
  169. }
  170. #endif
  171.  
  172. /* daemons to be run at startup time */
  173. struct daemon Daemons[] = 
  174. {
  175.     { "killer",    512,    killer },
  176. #ifndef ATARI
  177.     { "gcollect",    256,    gcollect },
  178. #endif
  179.     { "timer",    1024,    timerproc },
  180.     { "network",    1536,    network },
  181.     { "keyboard",    250,    keyboard },
  182.     { NULLCHAR,    0,    NULLVFP }
  183. }
  184. ;
  185.  
  186. struct iftype Iftypes[] = 
  187. {
  188.     /* This entry must be first, since Loopback refers to it */
  189.     { "None",        NULL,        NULL,        NULL,
  190.       NULL,        CL_NONE,    0 },
  191.  
  192. #ifdef    AX25
  193.     { "AX25",        ax_send,    ax_output,    pax25,
  194.       setcall,    CL_AX25,    AXALEN },
  195. #endif
  196.  
  197. #ifdef    SLIP
  198.     { "SLIP",        slip_send,    NULL,        NULL,
  199.       NULL,        CL_NONE,    0 },
  200. #endif
  201.  
  202. #ifdef    ETHER
  203.     /* Note: NULL is specified for the scan function even though
  204.      * gether() exists because the packet drivers don't support
  205.      * address setting.
  206.      */
  207.     { "Ethernet",    enet_send,    enet_output,    pether,
  208.       NULL,        CL_ETHERNET,    EADDR_LEN },
  209. #endif
  210.  
  211. #ifdef    NETROM
  212.     { "NETROM",    nr_send,    NULL,        pax25,
  213.       setcall,    CL_NETROM,    AXALEN },
  214. #endif
  215.  
  216. #ifdef    SLFP
  217.     { "SLFP",        pk_send,    NULL,        NULL,
  218.       NULL,        CL_NONE,    0 },
  219. #endif
  220.  
  221. #ifdef    PPP
  222.     { "PPP",        ppp_send,    ppp_output,    NULL,
  223.       NULL,        CL_PPP,    0 },
  224. #endif
  225.  
  226.     { NULLCHAR }
  227. }
  228. ;
  229.  
  230. /* Command lookup and branch tables */
  231. struct cmds far Cmds[] = 
  232. {
  233.     /* The "go" command must be first */
  234.     { "",        go,        0, 0, NULLCHAR },
  235. #ifndef    AMIGA
  236.     { "!",        doshell,    0, 0, NULLCHAR },
  237. #endif
  238.     { "abort",    doabort,    0, 0, NULLCHAR },
  239. #ifdef    AMIGA
  240.     { "amiga",    doamiga,    0, 0, NULLCHAR },
  241. #endif
  242. #if    (defined(MAC) && defined(APPLETALK))
  243.     { "applestat",    doatstat,    0,    0, NULLCHAR },
  244. #endif
  245. #if    (defined(AX25) || defined(ETHER) || defined(APPLETALK))
  246.     { "arp",        doarp,        0, 0, NULLCHAR },
  247. #endif
  248. #ifdef    ASY
  249.     { "asystat",    doasystat,    0, 0, NULLCHAR },
  250. #endif
  251. #ifdef ATCMD
  252.     { "at",       doat,       0, 0, NULLCHAR },
  253. #endif
  254.     { "attach",    doattach,    0, 2,
  255.     "attach <hardware> <hw specific options>" },
  256. #ifdef    AX25
  257.     { "ax25",        doax25,        0, 0, NULLCHAR },
  258. #endif
  259. #ifdef    BOOTP
  260.     { "bootp",    dobootp,    0, 0, NULLCHAR },
  261.     { "bootpd",    bootpdcmd,    0, 0, NULLCHAR },
  262. #endif
  263. /* This one is out of alpabetical order to allow abbreviation to "c" */
  264. #ifdef    AX25
  265.     { "connect",    doconnect,    1024, 3,
  266.     "connect <interface> <callsign>" },
  267. #endif
  268. #if    !defined(UNIX) && !defined(AMIGA)
  269.     { "cd",        docd,        0, 0, NULLCHAR },
  270. #endif
  271. #ifdef ATARI
  272.     { "clear", doclear, 0, 0, NULLCHAR },
  273. #endif
  274.     { "close",    doclose,    0, 0, NULLCHAR },
  275. /* This one is out of alpabetical order to allow abbreviation to "d" */
  276.     { "disconnect",    doclose,    0, 0, NULLCHAR },
  277.     { "delete",    dodelete,    0, 2, "delete <file>" },
  278.     { "detach",    dodetach,    0, 2, "detach <interface>" },
  279. #ifdef    DIALER
  280.     { "dialer",    dodialer,    512, 2,
  281.     "dialer <iface> [<file> [<seconds> [<pings> [<hostid>]]]]" },
  282. #endif
  283. #ifndef    AMIGA
  284.     { "dir",        dodir,        512, 0, NULLCHAR }, /* note sequence */
  285. #endif
  286.     { "domain",    dodomain,    0, 0, NULLCHAR },
  287. #ifdef    DRSI
  288.     { "drsistat",    dodrstat,    0, 0, NULLCHAR },
  289. #endif
  290. #ifdef    EAGLE
  291.     { "eaglestat",    doegstat,    0, 0, NULLCHAR },
  292. #endif
  293.     { "echo",        doecho,        0, 0, NULLCHAR },
  294.     { "eol",        doeol,        0, 0, NULLCHAR },
  295.     { "escape",    doescape,    0, 0, NULLCHAR },
  296. #ifdef    PC_EC
  297.     { "etherstat",    doetherstat,    0, 0, NULLCHAR },
  298. #endif
  299.     { "exit",        doexit,        0, 0, NULLCHAR },
  300.     { "finger",    dofinger,    1024, 2, "finger name@host" },
  301. #ifdef ALLCMD
  302.     { "fkey",        dofkey,        0, 0, NULLCHAR },
  303. #endif
  304.      { "ftp",        doftp,        2048, 1, "ftp [<address>]" },
  305.     { "ftpopt",        doftpopt,    0, 2,
  306.        "ftpopt verbose | hash | byte | type | ascii | binary | pager | wrap" },
  307. #ifdef HAPN
  308.     { "hapnstat",    dohapnstat,    0, 0, NULLCHAR },
  309. #endif
  310.     { "help",        dohelp,        0, 0, NULLCHAR },
  311. #ifdef    HOPCHECK
  312.     { "hop",        dohop,        0, 0, NULLCHAR },
  313. #endif
  314.     { "hostname",    dohostname,    0, 0, NULLCHAR },
  315. #ifdef    HS
  316.     { "hs",        dohs,        0, 0, NULLCHAR },
  317. #endif
  318.     { "icmp",        doicmp,        0, 0, NULLCHAR },
  319.     { "ifconfig",    doifconfig,    0, 0, NULLCHAR },
  320. #ifdef    DIALER
  321.     { "inline",    do_inline,    0, 0, NULLCHAR },
  322. #endif
  323.     { "ip",        doip,        0, 0, NULLCHAR },
  324. #ifdef    MSDOS
  325.     { "isat",        doisat,        0, 0, NULLCHAR },
  326. #endif
  327.     { "kick",        dokick,        0, 0, NULLCHAR },
  328.     { "log",        dolog,        0, 0, NULLCHAR },
  329. #ifdef    MAILBOX
  330.     { "mbox",        dombox,        0, 0, NULLCHAR },
  331. #endif
  332. #ifndef    UNIX
  333.     { "memory",    domem,        0, 0, NULLCHAR },
  334. #endif
  335.     { "mkdir",    domkd,        0, 2, "mkdir <directory>" },
  336. #ifdef    AX25
  337.     { "mode",        domode,        0, 2, "mode <interface>" },
  338. #endif
  339.     { "more",        domore,        512, 2, "more <filename>" },
  340. #ifdef MULTITASK
  341.     { "multitask",    dobackg,    0, 0, NULLCHAR },
  342. #endif
  343. #ifdef    NETROM
  344.     { "netrom",    donetrom,    0, 0, NULLCHAR },
  345. #endif    /* NETROM */
  346. #ifdef    NNTP
  347.     { "nntp",        donntp,        0, 0, NULLCHAR },
  348. #endif    /* NNTP */
  349. #ifdef NOVEL
  350.     { "novell",    donovell,    0, 0, NULLCHAR },
  351. #endif
  352. #ifdef    NRS
  353.     { "nrstat",    donrstat,    0, 0, NULLCHAR },
  354. #endif    /* NRS */
  355.     { "param",    doparam,    0, 2, "param <interface>" },
  356.     { "ping",        doping,        512, 2,
  357.     "ping <hostid> [<length> [<interval> [incflag]]]" },
  358. #ifdef    PI
  359.     { "pistatus",    dopistat,    0, 0, NULLCHAR },
  360. #endif
  361. #ifdef POP
  362.     { "pop",        dopop,        0, 0, NULLCHAR },
  363. #endif
  364. #ifdef PPP
  365.     { "ppp",        doppp_commands,    0, 0, NULLCHAR },
  366. #endif
  367.     { "ps",        ps,        0, 0, NULLCHAR },
  368. #if    !defined(UNIX) && !defined(AMIGA)
  369.     { "pwd",        docd,        0, 0, NULLCHAR },
  370. #endif
  371.     { "record",    dorecord,    0, 0, NULLCHAR },
  372.     { "remote",    doremote,    0, 3, "remote [-p port] [-k key] [-a kickaddr] <address> exit|reset|kick" },
  373.     { "rename",    dorename,    0, 3, "rename <oldfile> <newfile>" },
  374.     { "reset",    doreset,    0, 0, NULLCHAR },
  375. #ifdef    RIP
  376.     { "rip",        dorip,        0, 0, NULLCHAR },
  377. #endif
  378.     { "rsh",        dorsh,        2048, 3, "rsh <address> <command>" },
  379.     { "rlogin",    dorlogin,    2048, 2, "rlogin <address>" },
  380.     { "rmdir",    dormd,        0, 2, "rmdir <directory>" },
  381.     { "route",    doroute,    0, 0, NULLCHAR },
  382.     { "session",    dosession,    0, 0, NULLCHAR },
  383. #ifdef    SCC
  384.     { "sccstat",    dosccstat,    0, 0, NULLCHAR },
  385. #endif
  386. #if    !defined(AMIGA)
  387.     { "shell",    doshell,    0, 0, NULLCHAR },
  388. #endif
  389.     { "smtp",        dosmtp,        0,     0, NULLCHAR },
  390.     { "socket",        dosock,        0,     0, NULLCHAR },
  391.     { "source",        dosource,    0,     2, "source <filename>" },
  392.     { "sourceb",    dosourceb,    1024, 2, "source <filename>" },
  393. #ifdef    SERVERS
  394.     { "start",    dostart,    0, 2, "start <servername>" },
  395.     { "stop",        dostop,        0, 2, "stop <servername>" },
  396. #endif
  397.     { "tcp",        dotcp,        0, 0, NULLCHAR },
  398.     { "telnet",    dotelnet,    1024, 2, "telnet <address>" },
  399.     { "test",        dotest,        0, 0, NULLCHAR },
  400.     { "time",        do_time,    0,    1,    "time <server | read | set>" },
  401.     { "tip",        dotip,        256, 2, "tip <iface>" },
  402. #ifdef    TRACE
  403.     { "trace",    dotrace,    0, 0, NULLCHAR },
  404. #endif
  405.     { "udp",        doudp,        0, 0, NULLCHAR },
  406.     { "upload",    doupload,    0, 0, NULLCHAR },
  407. #ifdef    MSDOS
  408.     { "watch",    doswatch,    0, 0, NULLCHAR },
  409. #endif
  410.     { "?",        dohelp,        0, 0, NULLCHAR },
  411.     { NULLCHAR,    NULLFP,        0, 0,
  412.     "Unknown command; type \"?\" for list" },
  413. }
  414. ;
  415.  
  416. /* List of supported hardware devices */
  417. struct cmds Attab[] = 
  418. {
  419. #ifdef    PC_EC
  420.     /* 3-Com Ethernet interface */
  421.     { "3c500", ec_attach, 0, 7,
  422.     "attach 3c500 <address> <vector> arpa <label> <buffers> <mtu> [ip_addr]" },
  423. #endif
  424. #ifdef    ASY
  425.     /* Ordinary PC asynchronous adaptor */
  426.     { "asy", asy_attach, 0, 8,
  427. #    ifndef    AMIGA
  428.     "attach asy <address> <vector> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]" },
  429. #    else
  430.     "attach asy <driver> <unit> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]" },
  431. #    endif    /* AMIGA */
  432. #endif    /* ASY */
  433. #ifdef    PC100
  434.     /* PACCOMM PC-100 8530 HDLC adaptor */
  435.     { "pc100", pc_attach, 0, 8,
  436.     "attach pc100 <address> <vector> ax25 <label> <buffers>\
  437.  <mtu> <speed> [ip_addra] [ip_addrb]" },
  438. #endif
  439. #ifdef    DRSI
  440.     /* DRSI PCPA card in low speed mode */
  441.     { "drsi", dr_attach, 0, 8,
  442.     "attach drsi <address> <vector> ax25 <label> <bufsize> <mtu>\
  443. <chan a speed> <chan b speed> [ip addr a] [ip addr b]" },
  444. #endif
  445. #ifdef    EAGLE
  446.     /* EAGLE RS-232C 8530 HDLC adaptor */
  447.     { "eagle", eg_attach, 0, 8,
  448.     "attach eagle <address> <vector> ax25 <label> <buffers>\
  449.  <mtu> <speed> [ip_addra] [ip_addrb]" },
  450. #endif
  451. #ifdef    PI
  452.     /* PI 8530 HDLC adaptor */
  453.     { "pi", pi_attach, 0, 8,
  454.     "attach pi <address> <vector> <dmachannel> ax25 <label> <buffers>\
  455.  <mtu> <speed> [ip_addra] [ip_addrb]" },
  456. #endif
  457. #ifdef    HAPN
  458.     /* Hamilton Area Packet Radio (HAPN) 8273 HDLC adaptor */
  459.     { "hapn", hapn_attach, 0, 8,
  460.     "attach hapn <address> <vector> ax25 <label> <rx bufsize>\
  461.  <mtu> csma|full [ip_addr]" },
  462. #endif
  463. #ifdef    APPLETALK
  464.     /* Macintosh AppleTalk */
  465.     { "0", at_attach, 0, 7,
  466.     "attach 0 <protocol type> <device> arpa <label> <rx bufsize> <mtu> [ip_addr]" },
  467. #endif
  468. #ifdef NETROM
  469.     /* fake netrom interface */
  470.     { "netrom", nr_attach, 0, 1,
  471.     "attach netrom [ip_addr]" },
  472. #endif
  473. #ifdef    PACKET
  474.     /* FTP Software's packet driver spec */
  475.     { "packet", pk_attach, 0, 4,
  476.     "attach packet <int#> <label> <buffers> <mtu> [ip_addr]" },
  477. #endif
  478. #ifdef    HS
  479.     /* Special high speed driver for DRSI PCPA or Eagle cards */
  480.     { "hs", hs_attach, 0, 7,
  481.     "attach hs <address> <vector> ax25 <label> <buffers> <mtu>\
  482.  <txdelay> <persistence> [ip_addra] [ip_addrb]" },
  483. #endif
  484. #ifdef SCC
  485.     { "scc", scc_attach, 0, 7,
  486.     "attach scc <devices> init <addr> <spacing> <Aoff> <Boff> <Dataoff>\n"
  487.     "   <intack> <vec> [p]<clock> [hdwe] [param]\n"
  488.     "attach scc <chan> slip|kiss|nrs|ax25 <label> <mtu> <speed> <bufsize> [call] " },
  489. #endif
  490.     { NULLCHAR },
  491. }
  492. ;
  493.  
  494. /* Functions to be called on each clock tick */
  495. void (*Cfunc[]) __ARGS((void)) = 
  496. {
  497. #ifndef ATARI    
  498.     pctick,    /* Call PC-specific stuff to keep time */
  499.     kbint,    /* Necessary because there's no hardware keyboard interrupt */
  500.     refiq,    /* Replenish interrupt pool */
  501. #endif
  502. #ifdef    ASY
  503. #ifndef ATARI
  504.     asytimer,
  505. #endif
  506. #endif
  507. #ifdef    SCC
  508.     scctimer,
  509. #endif
  510.     NULL,
  511. }
  512. ;
  513.  
  514. /* Entry points for garbage collection */
  515. void (*Gcollect[])() = 
  516. {
  517.     tcp_garbage,
  518.     ip_garbage,
  519.     udp_garbage,
  520.     st_garbage,
  521. #ifdef    AX25
  522.     lapb_garbage,
  523. #endif
  524. #ifdef    NETROM
  525.     nr_garbage,
  526. #endif
  527.     NULL
  528. }
  529. ;
  530.  
  531. /* Functions to be called at shutdown */
  532. void (*Shutdown[])() = 
  533. {
  534. #ifdef    SCC
  535.     sccstop,
  536. #endif
  537. #ifndef ATARI
  538.     uchtimer,    /* Unlink timer handler from timer chain */
  539. #endif
  540.     NULLVFP,
  541. }
  542. ;
  543.  
  544. /* Packet tracing stuff */
  545. #ifdef    TRACE
  546. #include "trace.h"
  547.  
  548. /* Protocol tracing function pointers. Matches list of class definitions
  549.  * in pktdrvr.h.
  550.  */
  551. struct trace Tracef[] = 
  552. {
  553.     { NULLFP,        ip_dump },    /* CL_NONE */
  554.  
  555. #    ifdef    ETHER                /* CL_ETHERNET */
  556.     { ether_forus,    ether_dump },
  557. #    else
  558.     { NULLFP,        NULLVFP },
  559. #    endif    /* ETHER */
  560.  
  561.     { NULLFP,        NULLVFP },    /* CL_PRONET_10 */
  562.     { NULLFP,        NULLVFP },    /* CL_IEEE8025 */
  563.     { NULLFP,        NULLVFP },    /* CL_OMNINET */
  564.  
  565. #    ifdef    APPLETALK
  566.     { at_forus,    at_dump },    /* CL_APPLETALK */
  567. #    else
  568.     { NULLFP,        NULLVFP },
  569. #    endif    /* APPLETALK */
  570.  
  571. #    ifdef VJCOMPRESS
  572.     { NULLFP,        sl_dump },    /* CL_SERIAL_LINE */
  573. #    else
  574.     { NULLFP,        ip_dump },    /* CL_SERIAL_LINE */
  575. #    endif
  576.     { NULLFP,        NULLVFP },    /* CL_STARLAN */
  577.  
  578. #    ifdef    ARCNET
  579.     { arc_forus,    arc_dump },    /* CL_ARCNET */
  580. #    else
  581.     { NULLFP,        NULLVFP },
  582. #    endif    /* ARCNET */
  583.  
  584. #    ifdef    AX25
  585.     { ax_forus,    ax25_dump },    /* CL_AX25 */
  586. #    else
  587.     { NULLFP,        NULLVFP },
  588. #    endif    /* AX25 */
  589.  
  590. #    ifdef    KISS                /* CL_KISS */
  591.     { ki_forus,    ki_dump },
  592. #    else
  593.     { NULLFP,        NULLVFP },
  594. #    endif    /* KISS */
  595.  
  596.     { NULLFP,        NULLVFP },    /* CL_IEEE8023 */
  597.     { NULLFP,        NULLVFP },    /* CL_FDDI */
  598.     { NULLFP,        NULLVFP },    /* CL_INTERNET_X25 */
  599.     { NULLFP,        NULLVFP },    /* CL_LANSTAR */
  600.     { NULLFP,        ip_dump },    /* CL_SLFP */
  601.  
  602. #    ifdef    NETROM                /* CL_NETROM */
  603.     { NULLFP,        ip_dump },
  604. #    else
  605.     { NULLFP,        NULLVFP },
  606. #    endif
  607.  
  608. #    ifdef PPP
  609.     { NULLFP,        ppp_dump },    /* CL_PPP */
  610. #    else
  611.     { NULLFP,        NULLVFP },
  612. #    endif /* PPP */
  613. }
  614. ;
  615.  
  616. #else    /* TRACE */
  617.  
  618. /* Stub for packet dump function */
  619. void
  620. dump(iface,direction,type,bp)
  621. struct iface *iface;
  622. int direction;
  623. unsigned type;
  624. struct mbuf *bp;
  625. {
  626. }
  627. void
  628. raw_dump(iface,direction,bp)
  629. struct iface *iface;
  630. int direction;
  631. struct mbuf *bp;
  632. {
  633. }
  634.  
  635. #endif    /* TRACE */
  636.  
  637.  
  638. #ifdef    AX25
  639. /* Hooks for passing incoming AX.25 data frames to network protocols */
  640. static void
  641. axip(iface,axp,src,dest,bp,mcast)
  642. struct iface *iface;
  643. struct ax25_cb *axp;
  644. char *src;
  645. char *dest;
  646. struct mbuf *bp;
  647. int mcast;
  648. {
  649.     (void)ip_route(iface,bp,mcast);
  650. }
  651.  
  652. static void
  653. axarp(iface,axp,src,dest,bp,mcast)
  654. struct iface *iface;
  655. struct ax25_cb *axp;
  656. char *src;
  657. char *dest;
  658. struct mbuf *bp;
  659. int mcast;
  660. {
  661.     (void)arp_input(iface,bp);
  662. }
  663.  
  664. #    ifdef    NETROM
  665. static void
  666. axnr(iface,axp,src,dest,bp,mcast)
  667. struct iface *iface;
  668. struct ax25_cb *axp;
  669. char *src;
  670. char *dest;
  671. struct mbuf *bp;
  672. int mcast;
  673. {
  674.     if(!mcast)
  675.         nr_route(bp,axp);
  676.     else
  677.         nr_nodercv(iface,src,bp);
  678. }
  679.  
  680. #    endif    /* NETROM */
  681. #endif    /* AX25 */
  682.  
  683. #ifndef    RIP
  684. /* Stub for routing timeout when RIP is not configured -- just remove entry */
  685. void
  686. rt_timeout(s)
  687. void *s;
  688. {
  689.     struct route *stale = (struct route *)s;
  690.  
  691.     rt_drop(stale->target,stale->bits);
  692. }
  693. #endif
  694.  
  695. #ifdef    SERVERS
  696. /* "start" and "stop" subcommands */
  697. static struct cmds Startcmds[] = 
  698. {
  699. #    if    defined(AX25) && defined(MAILBOX)
  700.     { "ax25",        ax25start,    256, 0, NULLCHAR },
  701. #    endif
  702.     { "discard",    dis1,        256, 0, NULLCHAR },
  703.     { "echo",        echo1,        256, 0, NULLCHAR },
  704.     { "finger",    finstart,    256, 0, NULLCHAR },
  705.     { "ftp",        ftpstart,    256, 0, NULLCHAR },
  706. #    if    defined(NETROM) && defined(MAILBOX)
  707.     { "netrom",    nr4start,    256, 0, NULLCHAR },
  708. #    endif
  709. #    ifdef POP
  710.     { "pop",        pop1,        256, 0, NULLCHAR },
  711. #    endif
  712. #    ifdef    RIP
  713.     { "rip",        doripinit,    0,   0, NULLCHAR },
  714. #    endif
  715.     { "smtp",        smtp1,        256, 0, NULLCHAR },
  716. #    if    defined(MAILBOX)
  717.     { "telnet",    telnet1,    256, 0, NULLCHAR },
  718.     { "time",        timestart,    256, 0, NULLCHAR },
  719.     { "tip",        tipstart,    256, 2, "start tip <interface>" },
  720. #    endif
  721.     { "ttylink",    ttylstart,    256, 0, NULLCHAR },
  722.     { "remote",    rem1,        768, 0, NULLCHAR },
  723.     { NULLCHAR },
  724. }
  725. ;
  726. static struct cmds Stopcmds[] = 
  727. {
  728. #    if    defined(AX25) && defined(MAILBOX)
  729.     { "ax25",        ax250,        0, 0, NULLCHAR },
  730. #    endif
  731.     { "discard",    dis0,        0, 0, NULLCHAR },
  732.     { "echo",        echo0,        0, 0, NULLCHAR },
  733.     { "finger",    fin0,        0, 0, NULLCHAR },
  734.     { "ftp",        ftp0,        0, 0, NULLCHAR },
  735. #    if    defined(NETROM) && defined(MAILBOX)
  736.     { "netrom",    nr40,        0, 0, NULLCHAR },
  737. #    endif
  738. #    ifdef    POP
  739.     { "pop",        pop0,        0, 0, NULLCHAR },
  740. #    endif
  741. #    ifdef    RIP
  742.     { "rip",        doripstop,    0, 0, NULLCHAR },
  743. #    endif
  744.     { "smtp",        smtp0,        0, 0, NULLCHAR },
  745. #    ifdef    MAILBOX
  746.     { "telnet",    telnet0,    0, 0, NULLCHAR },
  747.     { "time",        time0,        0, 0, NULLCHAR },
  748.     { "tip",        tip0,        0, 2, "stop tip <interface>" },
  749. #    endif
  750.     { "ttylink",    ttyl0,        0, 0, NULLCHAR },
  751.     { "remote",    rem0,        0, 0, NULLCHAR },
  752.     { NULLCHAR },
  753.  
  754. }
  755. ;
  756. static int
  757. dostart(argc,argv,p)
  758. int argc;
  759. char *argv[];
  760. void *p;
  761. {
  762.     return subcmd(Startcmds,argc,argv,p);
  763. }
  764. static int
  765. dostop(argc,argv,p)
  766. int argc;
  767. char *argv[];
  768. void *p;
  769. {
  770.     return subcmd(Stopcmds,argc,argv,p);
  771. }
  772. #endif    /* SERVERS */
  773.  
  774. /* Various configuration-dependent functions */
  775.  
  776. /* put mbuf into Hopper for network task
  777.  * returns 0 if OK
  778.  */
  779. int
  780. net_route(ifp, type, bp)
  781. struct iface *ifp;
  782. int type;
  783. struct mbuf *bp;
  784. {
  785.     struct mbuf *nbp;
  786.     struct phdr phdr;
  787.  
  788.     phdr.iface = ifp;
  789.     phdr.type = type;
  790.  
  791.     if ((nbp = pushdown(bp,sizeof(phdr))) == NULLBUF )
  792.     {
  793.         return -1;
  794.     }
  795.     memcpy( &nbp->data[0],(char *)&phdr,sizeof(phdr));
  796.     enqueue(&Hopper,nbp);
  797.     /* Especially on slow machines, serial I/O can be quite
  798.      * compute intensive, so release the machine before we
  799.      * do the next packet.  This will allow this packet to
  800.      * go on toward its ultimate destination. [Karn]
  801.      */
  802.     pwait(NULL);
  803.     return 0;
  804. }
  805.  
  806.  
  807. /* Process packets in the Hopper */
  808. static void
  809. network(i,v1,v2)
  810. int i;
  811. void *v1;
  812. void *v2;
  813. {
  814.     struct mbuf *bp;
  815.     struct phdr phdr;
  816.     char i_state;
  817.  
  818. loop:
  819. #ifndef ATARI
  820.     refiq();    /* Replenish interrupt buffer pool */
  821. #endif
  822.     i_state = dirps();
  823.     while(Hopper == NULLBUF)
  824.         pwait(&Hopper);
  825.     restore(i_state);
  826.  
  827.     /* Process the input packet */
  828.     bp = dequeue(&Hopper);
  829.     pullup(&bp,(char *)&phdr,sizeof(phdr));
  830.     if(phdr.iface != NULLIF)
  831.     {
  832.         phdr.iface->rawrecvcnt++;
  833.         phdr.iface->lastrecv = secclock();
  834.     }
  835.     dump(phdr.iface,IF_TRACE_IN,phdr.type,bp);
  836.     switch(phdr.type)
  837.     {
  838. #ifdef    KISS
  839.     case CL_KISS:
  840.         kiss_recv(phdr.iface,bp);
  841.         break;
  842. #endif
  843. #ifdef    AX25
  844.     case CL_AX25:
  845.         ax_recv(phdr.iface,bp);
  846.         break;
  847. #endif
  848. #ifdef    ETHER
  849.     case CL_ETHERNET:
  850.         eproc(phdr.iface,bp);
  851.         break;
  852. #endif
  853. #ifdef ARCNET
  854.     case CL_ARCNET:
  855.         aproc(phdr.iface,bp);
  856.         break;
  857. #endif
  858. #ifdef PPP
  859.     case CL_PPP:
  860.         ppp_proc(phdr.iface,bp);
  861.         break;
  862. #endif
  863.         /* These types have no link layer protocol at the point when they're
  864.          * put in the hopper, so they can be handed directly to IP. The
  865.          * separate types are just for user convenience when running the
  866.          * "iface" command.
  867.          */
  868.     case CL_NONE:
  869.     case CL_SERIAL_LINE:
  870.     case CL_SLFP:
  871.         ip_route(phdr.iface,bp,0);
  872.         break;
  873.     default:
  874.         free_p(bp);
  875.         break;
  876.     }
  877.     /* Let everything else run - this keeps the system from wedging
  878.      * when we're hit by a big burst of packets
  879.      */
  880.     pwait(NULL);
  881.     goto loop;
  882. }
  883.  
  884. int
  885. dotest(argc,argv,p)
  886. int argc;
  887. char *argv[];
  888. void *p;
  889. {
  890.     long i;
  891.     int32 oldtime = 0;
  892.     int32 newtime;
  893.  
  894.     Current->flowmode = 1;
  895.     for(i=0L; i<40000L; i++)
  896.     {
  897.         newtime = msclock();
  898.         if(newtime < oldtime)
  899.         {
  900.             tprintf("Clock slip %ld: %ld - %ld = %ld\n",i,
  901.               newtime,oldtime,newtime-oldtime);
  902.         }
  903.         else
  904.             oldtime = newtime;
  905.     }
  906.     pwait(NULL);
  907.     Current->flowmode = 0;
  908.     return 0;
  909. }
  910.  
  911.